package com.adcc.loadsheet.billing.security;

import com.google.common.base.Strings;

import javax.servlet.http.Cookie;

/**
 * Created by wyb on 2019/11/26.
 * cookie工具类
 */
public class CookieUtil {
    /**
     * 设置cookie
     * @param key
     * @param value
     * @param expireTime
     * @param uri
     * @param isHttpOnly
     * @return
     */
    public static Cookie setCookie(String key,String value,int expireTime,String uri,boolean isHttpOnly){
        Cookie cookie=new Cookie(key,value);
        cookie.setMaxAge(expireTime); //设置存活时间为0.此时cookies就会自动注销
        if(!Strings.isNullOrEmpty(uri)){
            cookie.setPath(uri);
        }
        cookie.setHttpOnly(isHttpOnly);
        return cookie;
    }
}
